package com.xs.designpattern;

import lombok.extern.slf4j.Slf4j;

import java.util.Arrays;
import java.util.stream.Stream;

/**
 * 这是一个抽象矮人工人类，包含了矮人工人的基本行为和操作
 * @author xs
 */
@Slf4j
public abstract class DwarvenMineWorker {
    public void goToSleep() {
        log.info("{} 去睡觉.", name());
    }

    public void wakeUp() {
        log.info("{} 醒来.", name());
    }

    public void goHome() {
        log.info("{} 回家.", name());
    }

    public void goToMine() {
        log.info("{} 去矿井.", name());
    }

    private void action(Action action) {
        switch (action) {
            case GO_TO_SLEEP:
                goToSleep();
                break;
            case WAKE_UP:
                wakeUp();
                break;
            case GO_HOME:
                goHome();
                break;
            case GO_TO_MINE:
                goToMine();
                break;
            case WORK:
                work();
                break;
            default:
                log.info("未定义的动作");
        }
    }

    /**
     * 执行操作
     */
    public void action(Action... actions) {
        Arrays.stream(actions).forEach(this::action);
    }

    public abstract void work();

    public abstract String name();

    enum Action {
        /**
         * 操作的枚举
         */
        GO_TO_SLEEP, WAKE_UP, GO_HOME, GO_TO_MINE, WORK
    }
}
